package com.xiaoyushu.xiaoyushu.auth.controller;

import com.xiaoyushu.framework.biz.operationlog.aspect.ApiOperationLog;
import com.xiaoyushu.framework.common.response.Response;
import com.xiaoyushu.xiaoyushu.auth.model.vo.user.UpdatePasswordReqVO;
import com.xiaoyushu.xiaoyushu.auth.model.vo.user.UserLoginReqVO;
import com.xiaoyushu.xiaoyushu.auth.service.AuthService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping
@Slf4j
public class AuthController
 {

    @Resource
    private AuthService userService;

     /**
      * type 等于1表示 用手机号短信登录
      * 等于2 表示用密码登录
      * @param userLoginReqVO
      * @return
      */
    @PostMapping("/login")
    @ApiOperationLog(description = "用户登录/注册")
    public Response<String> loginAndRegister(@Validated @RequestBody
                                             UserLoginReqVO userLoginReqVO) {
        return userService.loginAndRegister(userLoginReqVO);
    }

     @PostMapping("/logout")
     @ApiOperationLog(description = "账号登出")
     public Response<?> logout() {


         // todo 账号退出登录逻辑待实现
         userService.logout();
         //log.info("===>网关透传过来的用户 ID:{}",userId);
       return  Response.success();
     }

     @PostMapping("/password/update")
     @ApiOperationLog(description = "修改密码")
     public Response<?> updatePassword(@Validated @RequestBody
                                       UpdatePasswordReqVO updatePasswordReqVO) {
         return userService.updatePassword(updatePasswordReqVO);
     }




 }